package com.aizhixin.lab.course.classes.repository;

import com.aizhixin.lab.course.classes.entity.LabReport;

import java.util.ArrayList;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface LabReportRepository extends JpaRepository<LabReport, String> {
	
	public List<LabReport> findAllByDeleteFlag(Integer deleteFlag);
	
	public List<LabReport> findAllByStuIdAndChaperIdAndDeleteFlag(Long stuId,Long chaperId,Integer deleteFlag);
	
	public long deleteByCourseClassId(String courseClassId);
	
	public long deleteByChaperId(Long chaperId);
	
	public long countByCourseClassIdAndCommitTimeIsNotNull(String courseClassId);
	
	public long countByTeacherIdAndReviewResultAndDeleteFlag(Long teacherId,String reviewResult,Integer deleteFlag);
	
	public long countByStuIdAndReviewResultNotAndDeleteFlag(Long stuId,String reviewResult,Integer deleteFlag);
	
	public long countByStuIdAndReviewResultInAndDeleteFlag(Long stuId,List<String> reviewResults,Integer deleteFlag);
	
	public long countByChaperIdAndReviewResultAndDeleteFlag(Long chaperId,String reviewResult,Integer deleteFlag);
	
	@Modifying
    @Query(value="update t_lab_report as lr set lr.REVIEW_RESULT=:reviewResult where  lr.CHAPER_ID = :chaperId and lr.REVIEW_RESULT='init' and lr.DELETE_FLAG=:deleteFlag and lr.id <> :id ",nativeQuery=true)
    void updateByChaperId(@Param("reviewResult")String reviewResult,@Param("chaperId")Long chaperId,@Param("deleteFlag")Integer deleteFlag,@Param("id")String id);
	
	
	@Modifying
    @Query(value="update t_lab_report  set delete_flag=:deleteFlag where stu_id in :stuIds ",nativeQuery=true)
    void updateByStuId(@Param("deleteFlag")Integer deleteFlag,@Param("stuIds")List<Long> stuIds);
}
